<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 用户表的列表信息
 * @author chenhuan
 *
 */
class Userborrow extends CI_Controller {
	
	
	/**
	 * 代收明细
	 */
	function coll(){
		$page = intval($this->input->get_post('page'));
		$page = $page ? $page : 1;//默认第一页
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data['where']['user_id'] 	= $user_id;
		$data['where']['fstatus'] 	= 0;
		$data['select'] 	= 1;
		$data['order'] 		= 1;
		$data['page_size']  = 8;
		$data['page_start'] = ($page-1)*$data['page_size'];
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$tmpColl = array();
			$tmpColl['title'] 	= utf8substr($coll['title'], 0, 8);//标题
			$tmpColl['repay_time'] = date('m-d H:i', $coll['repay_time']);//应收时间
			$tmpColl['capital'] 	= number_format($coll['capital'], 2);//应收本金
			$tmpColl['interest'] 	= number_format($coll['interest'], 2);//应收利息
			$collection_list[] = $tmpColl;
		}
		echo json_encode($collection_list);
	}
	
	
	/**
	 * 已收明细
	 */
	function ycoll(){
		$page = intval($this->input->get_post('page'));
		$page = $page ? $page : 1;
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);
		if(!$user_id || $token!=$token_val){
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
		$data['where']['user_id'] 	= $user_id;
		$data['where']['fstatus'] 	= 1;
		$data['select'] 	= 1;
		$data['order'] 		= 4;
		$data['page_size']  = 8;
		$data['page_start'] = ($page-1)*$data['page_size'];
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$tmpColl = array();
			$tmpColl['title'] 	= utf8substr($coll['title'], 0, 8);//标题
			$tmpColl['repay_yestime'] = date('m-d H:i', $coll['repay_yestime']);//收款时间
			$tmpColl['capital'] 	= number_format($coll['capital'], 2);//本金
			$tmpColl['interest'] 	= number_format($coll['interest'], 2);//利息
			$collection_list[] = $tmpColl;
		}
		echo json_encode($collection_list);
	}
	
}
